package com.example.demo.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.example.demo.base.CommonPage;
import com.example.demo.dto.RolePageParam;
import com.example.demo.dto.RoleParam;
import com.example.demo.entity.Role;
import com.example.demo.mapper.RoleMapper;
import com.example.demo.service.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.util.LowCodeServiceUtil;
import com.example.demo.vo.RoleVO;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 系统管理-角色信息表 服务实现类
 * </p>
 *
 * @author vicente
 * @since 2024-01-24
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {

    @Override
    public boolean save(RoleParam param) {
        LowCodeServiceUtil.checkUnique(baseMapper,"code",param.getRoleKey(),null,"唯一编码已存在，请检查code参数");
        param.setRoleId(null);
        Role role = new Role();
        BeanUtil.copyProperties(param, role);
        return super.save(role);
    }

    @Override
    public boolean update(RoleParam param) {
        LowCodeServiceUtil.checkUnique(baseMapper,"code",param.getRoleKey(),param.getRoleId(),"唯一编码已存在，请检查code参数");
        Role role = new Role();
        BeanUtil.copyProperties(param, role);
        return super.updateById(role);
    }

    @Override
    public CommonPage<RoleVO> page(RolePageParam param) {
        return null;
    }

    @Override
    public RoleVO findById(Long id) {
        return null;
    }
}
